<template>
  <div>
    <div class="navbar">
      <el-menu
        :default-active="$route.path"
        class="el-menu-vertical-demo"
        @open="handleOpen"
        @close="handleClose"
        background-color="#545c64"
        text-color="#fff"
        active-text-color="#ffd04b"
      >
        <el-menu-item :index="item.path" v-for="item in navList" :key="item.id" @click="goto(item.path)">
          <i :class="item.icon"></i>
          <span slot="title">{{ item.title }}</span>
        </el-menu-item>
      </el-menu>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      navList: [
        {
          id: 1,
          title: "首页",
          path: "/home/page",
          icon: "el-icon-s-home"
        },
        {
          id: 2,
          title: "用户管理",
          path: "/home/user",
          icon: "el-icon-user-solid"
        },
        {
          id: 3,
          title: "商品管理",
          path: "/home/goods",
          icon: "el-icon-s-goods"
        },
        {
          id: 4,
          title: "定单管理",
          path: "/home/order",
          icon: "el-icon-tickets"
        }
      ]
    };
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    //跳转路由
    goto(path){
      this.$router.push(path)
    }
  }
};
</script>

<style lang="scss">
.navbar {
  position: absolute;
  width: 230px;
  top: 50px;
  left: 0px;
  bottom: 0px;
  overflow-y: auto;
  background-color: #545c64;
}
</style>